<template>
  <div>
    <div class="flex w-full items-center gap-2">
      <a-form :model="{}">
        <a-form-item :label="t['源门店']">
          <a-select v-model="from" :options="storeList"> </a-select>
        </a-form-item>
        <a-form-item :label="t['目标门店']">
          <a-select v-model="to" :options="storeList"> </a-select>
        </a-form-item>
      </a-form>
    </div>
    <div class="flex justify-center gap-2 mt-32">
      <a-button type="primary" :disabled="!from || !to" @click="asyncStore">
        {{ t["确定"] }}
      </a-button>
      <a-button @click="cancel">{{ t["取消"] }} </a-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { librarySync } from "@/api/service/library/library";
import { fetchStoreOptions } from "@/api/service/store/store";

const t = translate("公共模块");
const emit = defineEmits(["close"]);
const from = ref();
const to = ref();
const storeList = ref();
const getStoreList = async () => {
  const data = await fetchStoreOptions();
  storeList.value = data.data;
};

const cancel = () => {
  emit("close", false);
};
const asyncStore = async () => {
  await librarySync(from.value, to.value);
  emit("close");
};
onMounted(() => {
  getStoreList();
});
</script>

<style lang="scss" scoped>
.flex {
  white-space: nowrap;
}
</style>
